package salesforce.balancedsalesarray;

//找到数组的中间一个数，这个数左边所有数相加等于右边所有数
public class Solution {
    public int pivotIndex(int[] nums) {
        int total = 0;
        for (int i: nums ) {
            total += i;
        }

        int sumOfLeft = 0;
        for (int i = 0; i < nums.length; i++) {
            if (total - sumOfLeft - nums[i] == sumOfLeft){
                return i;
            }
            sumOfLeft += nums[i];
        }
        return -1;
    }
}
